package com.operator.Activitys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.operator.Activitys.R;
import com.operator.Activitys.adapter.base.BaseRecyclerViewAdapter;
import com.operator.Activitys.bean.RechargeList;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * 项目名称：金泽云 手机app
 * 类描述：充值记录 适配器
 * 创建人：张飞祥
 * 创建时间：2018/5/21 13:21
 * 修改人：张飞祥
 * 修改时间：2018/5/21 13:21
 * 修改备注：
 */
public class RechargeListAdapter extends BaseRecyclerViewAdapter {


    //上下文
    private Context mContext;
    //数据集合
    private List<RechargeList> mList;

    public RechargeListAdapter(Context mContext, List<RechargeList> mList) {
        super(mContext, mList);
        this.mContext = mContext;
        this.mList = mList;
    }


    @Override
    protected int getLayoutItemResId() {
        return R.layout.item_recharge_list;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        if (viewHolder instanceof RechargeViewHolder) {

            //TODO 获取充值记录 viewHolder
            final RechargeViewHolder holder = (RechargeViewHolder) viewHolder;
            //TODO  将数据保存在itemView的Tag中，以便点击时进行获取
            holder.itemView.setTag(position);
            //TODO  获取数据源 第 i 个 实体数据
            RechargeList rechargeList = mList.get(position);

            /**
             * 设置数据源
             */
            //充值时间
            holder.tvItemRechargeTime.setText(rechargeList.getCreateTime());
            //充值钱数
            holder.tvItemRechargeMoney.setText("+ "+rechargeList.getMoney()+"元");


        }
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new RechargeViewHolder(view);
    }

    /**
     * ViewHolder
     */
    public class RechargeViewHolder extends RecyclerView.ViewHolder {

        //充值时间
        TextView tvItemRechargeTime;
        //充值钱数
        TextView tvItemRechargeMoney;

        public RechargeViewHolder(View itemView) {
            super(itemView);
            /**
             * 初始化控件
             */
            //充值时间
            tvItemRechargeTime = itemView.findViewById(R.id.tv_item_recharge_time);
            //充值钱数
            tvItemRechargeMoney = itemView.findViewById(R.id.tv_item_recharge_money);

            //屏幕适配
            AutoUtils.autoSize(itemView);
        }
    }
}
